package com.kkb.shopcenter.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.shopcenter.api.UserInfoService;
import com.kkb.shopcenter.common.pojo.UserInfo;
import com.kkb.shopcenter.server.mappers.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public List<UserInfo> getAllUserInfo() {
       return userInfoMapper.selectAll();
    }

    @Override
    public int addUserInfo(UserInfo userInfo) {
        return userInfoMapper.insertSelective(userInfo);
    }

    @Override
    public int updateUserInfo(UserInfo userInfo) {
        return userInfoMapper.updateByPrimaryKeySelective(userInfo);
    }

    @Override
    public int deleteUserById(Long id) {
        return userInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<UserInfo> getPageUserInfo(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserInfo> allUserInfo = userInfoMapper.selectAll();
        PageInfo<UserInfo> pageInfo = new PageInfo<>(allUserInfo);
        return pageInfo;
    }

    @Override
    public UserInfo findByUsername(String username) {
        Example example = new Example(UserInfo.class);
        example.createCriteria().andEqualTo("userName",username);
        UserInfo userInfo = userInfoMapper.selectOneByExample(example);
        return userInfo;
    }
}
